$(function() {
	
	//启用拖拽
	Common.DragStart($(".newdiary_header")[0]);

	//关闭按钮
	$(".close").bind("click", function() {
		window.nativeWindow.close();
	});
	//内容高度
	var height = Const.diarynew._height - 104;
	$(".newdiary_body").height(height);

	//改变大小
	$(".resizebar").bind("mousedown", function() {
		window.nativeWindow.startResize("BR");
	});
	/********************************************************/
	//调整窗口大小时处理界面
	$(window).resize(function() {
		var nwHeight = window.nativeWindow.height;
		var height = nwHeight - 104;
		$(".newdiary_body").height(height);
	});
	//设置焦点
	$("#diarycontent").focus();

	//取消
	$("#btnCancel").bind("click", function() {
		window.nativeWindow.close();
	});
	//确定
	$("#btnConfirm").bind("click", function() {
		var diaryStr = $("#diarycontent").val();
		if(diaryStr.trim().length < 40) {
			Common.ShowTips("日记内容太少喽……");
			return;
		}
		ShowLoading();		
		App.saveDiary(diaryStr, function() {
			HideLoading();
			window.nativeWindow.close();
		}, function(err) {
			Common.ShowTips(err);
		});
	});
});
function ShowLoading() {
	$(".newdiary_loading").height(window.nativeWindow.height - 37);
	$(".newdiary_loading").show();
}

function HideLoading() {
	$(".newdiary_loading").hide();
}